import { globalPlayer } from 'python-player';
import { createPrimeNumberExample } from './prime-numbers.js';
import { createHelloWorldExample } from './hello-world.js';
import { createBasicExamplesFolder } from './basic-examples.js';
import { getProjectVersion } from '../../utils/version';

// 默认文件内容
export const DEFAULT_MAIN_PY_CONTENT = `# 欢迎使用 Python IDE
# 这是一个在线Python代码编辑器和执行环境

print('Hello, Python IDE!')
print('欢迎开始您的Python编程之旅！')`;

const createDefaultMainFile = () => {
  try {
    const file = globalPlayer.fs.createFileObject('main.py', {
      parentId: 0,
      mimeType: 'text/x-python',
      id: 1, // 使用数字ID
      opened: false
    });

    file.setContentSync(DEFAULT_MAIN_PY_CONTENT);
    
    // console.log('默认文件对象创建成功:', file.name, 'ID:', file.id, 'parentId:', file.parentId);
    return file;
  } catch (error) {
    console.error('创建默认文件对象失败:', error);
    throw error;
  }
};

// 默认的项目配置
const mainFile = createDefaultMainFile();
const primeFile = createPrimeNumberExample();
const helloFile = createHelloWorldExample();
const basicExamples = createBasicExamplesFolder();


export const defaultProject = {
  name: '新的作品',
  description: '这是一个新的Python作品项目',
  version: getProjectVersion(),
  config: {
    entryPoint: 'main.py'
  },
  activeFileId: mainFile.id,
  files: [
    mainFile,
    primeFile,
    helloFile,
    ...basicExamples,
  ]
};

